package com.ruoyi.backstage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zzw.domain.TagManage;
import com.ruoyi.zzw.service.TTagManageService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 标签管理Controller
 * 
 * @author ruoyi
 * @date 2023-12-06
 */
@RestController
@RequestMapping("/backstage/tag")
public class BackTagManageController extends BaseController
{
    @Autowired
    private TTagManageService tTagManageService;

    /**
     * 查询标签管理列表
     */
    @PreAuthorize("@ss.hasPermi('tag:tag:list')")
    @GetMapping("/list")
    public AjaxResult list(TagManage tagManage)
    {
        List<TagManage> list = tTagManageService.selectTTagManageList(tagManage);
        return success(list);
    }

    /**
     * 导出标签管理列表
     */
    @PreAuthorize("@ss.hasPermi('tag:tag:export')")
    @Log(title = "标签管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TagManage tagManage)
    {
        List<TagManage> list = tTagManageService.selectTTagManageList(tagManage);
        ExcelUtil<TagManage> util = new ExcelUtil<TagManage>(TagManage.class);
        util.exportExcel(response, list, "标签管理数据");
    }

    /**
     * 获取标签管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('tag:tag:query')")
    @GetMapping(value = "/{cTagId}")
    public AjaxResult getInfo(@PathVariable("cTagId") Long cTagId)
    {
        return success(tTagManageService.selectTTagManageByCTagId(cTagId));
    }

    /**
     * 新增标签管理
     */
    @PreAuthorize("@ss.hasPermi('tag:tag:add')")
    @Log(title = "标签管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TagManage tagManage)
    {
        return toAjax(tTagManageService.insertTTagManage(tagManage));
    }

    /**
     * 修改标签管理
     */
    @PreAuthorize("@ss.hasPermi('tag:tag:edit')")
    @Log(title = "标签管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TagManage tagManage)
    {
        return toAjax(tTagManageService.updateTTagManage(tagManage));
    }

    /**
     * 删除标签管理
     */
    @PreAuthorize("@ss.hasPermi('tag:tag:remove')")
    @Log(title = "标签管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cTagIds}")
    public AjaxResult remove(@PathVariable Long[] cTagIds)
    {
        return toAjax(tTagManageService.deleteTTagManageByCTagIds(cTagIds));
    }
}
